<template>
  <div>
    <el-card>
      <div slot="header" class="clearfix">
        <span>样品订单详情</span>
      </div>
      <el-form
        ref="orderForm"
        :model="orderForm"
        :rules="formRule"
        label-position="right"
        label-width="120px"
        style="width:100%;flex-wrap:wrap"
        class="flex"
      >
        <el-form-item label="订单时间" prop="add_time" style="width:30%">
          <el-input v-model="orderForm.add_time" placeholder="" :disabled="isDisabled"></el-input>
        </el-form-item>
        <el-form-item label="订单号" prop="order_id" style="width:30%">
          <el-input v-model="orderForm.order_id" placeholder="" :disabled="isDisabled"></el-input>
        </el-form-item>
        <el-form-item label="收货人" prop="real_name" style="width:30%;">
          <el-input v-model="orderForm.real_name" placeholder="" :disabled="isDisabled"></el-input>
        </el-form-item>
        <el-form-item label="收货人手机号" prop="user_phone" style="width:30%;">
          <el-input v-model="orderForm.user_phone" placeholder="" :disabled="isDisabled"></el-input>
        </el-form-item>
        <el-form-item label="订单金额" prop="total_price" style="width:30%;">
          <el-input v-model="orderForm.total_price" placeholder="" :disabled="isDisabled"></el-input>
        </el-form-item>
        <el-form-item label="付款方式" prop="pay_type" style="width:30%;">
          <el-input v-model="orderForm.pay_type" placeholder="" :disabled="isDisabled"></el-input>
        </el-form-item>
        <el-form-item label="支付状态" prop="paid" style="width:30%;">
          <el-input v-model="orderForm.paid" placeholder="" :disabled="isDisabled"></el-input>
        </el-form-item>
        <el-form-item label="订单状态" prop="status" style="width:30%;">
          <el-input v-model="orderForm.status" placeholder="" :disabled="isDisabled"></el-input>
        </el-form-item>
        <!--<el-form-item label="收货人" prop="realName" style="width:30%;">
          <el-input v-model="orderForm.realName" placeholder="请输入收货人" :disabled="isDisabled"></el-input>
        </el-form-item>
        <el-form-item label="联系电话" prop="userPhone" style="width:30%;">
          <el-input v-model="orderForm.userPhone" placeholder="请输入联系电话" :disabled="isDisabled"></el-input>
        </el-form-item>-->
        <el-form-item label="收货地址" prop="user_address" style="width:30%;">
          <el-input v-model="orderForm.user_address" placeholder="请输入收货地址" :disabled="isDisabled"></el-input>
        </el-form-item>
      </el-form>
      <el-table :data="tableData" style="width: 100%" height="400" stripe>
        <el-table-column prop="product_id" label="AKS料号" align="center"></el-table-column>
        <el-table-column prop="product_id" label="制造商料号" align="center"></el-table-column>
        <el-table-column prop="cart_info_json.productInfo.manufacturer" label="供应商" align="center"></el-table-column>
        <el-table-column prop="cart_info_json.productInfo.price" label="单价" align="center"></el-table-column>
        <el-table-column prop="cart_info_json.cart_num" label="购买数量" align="center"></el-table-column>
        <el-table-column prop="status" label="状态" :formatter="formatStatus" align="center"></el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <div>
              <el-button type="text" @click="checkDetail(scope.row,scope.$index)">
                <p style="color:blue">查看详情</p>
              </el-button>
              <br />
              <el-button type="text" @click="checkTransport(scope.row,scope.$index)">
                <p style="color:blue">查看物流</p>
              </el-button>
              <br />
              <el-button type="text" @click="approvalSuccess(scope.row,scope.$index)" v-if="scope.row.status==0">
                <p style="color:green;">审批通过</p>
              </el-button>
              <!--<br />-->
              <el-button type="text" @click="approvalFail(scope.row,scope.$index)" v-if="scope.row.status==0">
                <p style="color:red;">审批不通过</p>
              </el-button>
              <br />
              <el-button type="text" @click="addnum(scope.row,scope.$index)" v-if="scope.row.status==0">
                <p style="color:blue;">修改数量</p>
              </el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <!--<el-dialog
          title="提示"
          :visible.sync="dialogVisible"
          width="30%"
          :before-close="handleClose">
          <span>是否确认订单</span>
          <span slot="footer" class="dialog-footer">
            <el-button @click="dialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="agreeOrder">确 定</el-button>
          </span>
        </el-dialog>
        <el-dialog
          title="提示"
          :visible.sync="redialogVisible"
          width="30%"
          :before-close="rehandleClose">
          <span>是否打回订单</span>
          <span slot="footer" class="dialog-footer">
            <el-button @click="redialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="refuseOrder">确 定</el-button>
          </span>
        </el-dialog>-->
      <el-pagination
        style="text-align:center;margin-top:20px"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
      <!--<div class="flex" style="justify-content:center;margin:15px 0" v-show="orderForm.paid==0" >
        <el-button type="primary" size="medium" v-if="isDisabled"  @click="dialogVisible = true">确认订单</el-button>
        <el-button type="danger" size="medium" style="margin-left:50px"  @click="redialogVisible = true" v-if="isDisabled">打回订单</el-button>
      </div>-->
    </el-card>
  </div>
</template>

<script>
import {
  ORDER_CART_LIST,
  ORDER_AGREE,ORDER_REFUSE
} from '@/utils/api';
import axios from 'axios'
export default {
  data() {
    return {
      dialogVisible: false,
      redialogVisible:false,
      orderForm: {},
      formRule: {},
      tableData: [
        // {
        //   AKSNo: "asda112312",
        //   producerNo: "123143424234",
        //   price: "1",
        //   unit: "件",
        //   puchaseQty: 500
        // }
      ],
      payOptions: [
        {
          value: "0",
          label: "未支付"
        },
        {
          value: "1",
          label: "已支付"
        },
        {
          value: "3",
          label: "线下处理"
        }
      ],
      payMethods: [
        {
          value: "0",
          label: "银行卡"
        },
        {
          value: "1",
          label: "线下支付"
        }
      ],
      orderOptions: [
        {
          value: "0",
          label: "未打回"
        },
        {
          value: "1",
          label: "已打回"
        },
        {
          value: "2",
          label: "未确认"
        }
      ],
      isDisabled: false,
      currentPage: 1,
      pageSize: 10,
      total: 0
    };
  },
  mounted() {
    if (this.$route.query["data"]) {
      this.isDisabled = this.$route.query["handler"] == "check" ? true : false;
      this.orderForm = this.$route.query["data"];
	  	if(this.orderForm.paid == 1){
	  		this.orderForm.paid = '已支付'
	  	}else if(this.orderForm.paid = 2){
	  		this.orderForm.paid = '线下审核'
	  	}else {
	  		this.orderForm.paid = '未支付'
	  	}
  	
			if(this.orderForm.status == 0){
				this.orderForm.status = "待付款"
			}else if(this.orderForm.status == 1){
				this.orderForm.status = "待收货"
			}else if(this.orderForm.status == 2){
				this.orderForm.status = "待发货"
			}else if(this.orderForm.status == 3){
				this.orderForm.status = "待评价"
			}else if(this.orderForm.status == 6){
				this.orderForm.status = "已评价"
			}else if(this.orderForm.status == -1){
				this.orderForm.status = "退换货订单"
			}else if(this.orderForm.status == 4){
				this.orderForm.status = "已完成"
			}
      this.getOrderList()
    }
  },
  methods: {
    rehandleClose(done) {
        this.$confirm('确认关闭？')
          .then(_ => {
            done();
          })
          .catch(_ => {});
    },
    handleClose(done) {
        this.$confirm('确认关闭？')
          .then(_ => {
            done();
          })
          .catch(_ => {});
    },
    refuseOrder(){
      ORDER_REFUSE({ 
          orderNum:this.orderForm.orderId,
      }).then(res => {
          this.$message.success('打回操作成功')
          this.getOrderList()
          this.redialogVisible=false
      })
    },
    agreeOrder(){
      ORDER_AGREE({ 
          orderNum:this.orderForm.orderId,
      }).then(res => {
          this.$message.success('同意操作成功')
          this.getOrderList()
          this.dialogVisible=false
      })
    },
    getOrderList(){
      let param = {
          id: this.orderForm.id
      }  // 创建form对象
      let config = {
        headers: {'Content-Type': 'application/json'}
      }
      var that=this
      axios.post('http://aml.foxcore.cn/api/v1/redirect/adminOrderGoodsList', param, config)
        .then(response => {
          console.log(response.data.data.goosList,'reee')
          for (var i = 0; i < response.data.data.goosList.length; i++) {
          	response.data.data.goosList[i].cart_info_json = JSON.parse(response.data.data.goosList[i].cart_info)
          }
          this.tableData = response.data.data.goosList
//        this.total = response.data.data.all_count
//	        for(let i in this.tableData){
//	        	this.tableData[i].add_time = this.formatSecond(this.tableData[i].add_time)
//	        }
        })
//    ORDER_CART_LIST({ 
//        cartIds:(''+this.orderForm.cartId).replace('\[','').replace('\]',''),
//        pageNo: this.currentPage,
//        pageSize: this.pageSize
//    }).then(res => {
//      var tempOrder=[]
//      for (var i=0;i<res.data.dataList.length;i++) {
//        var temp=res.data.dataList[i]
//        var obj=JSON.parse(temp.cartInfo);        
//        tempOrder.push(obj);   
//      }
//        this.tableData = tempOrder
//        this.total = res.data.count
//    })
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageSize=val
      this.getOrderList()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage=val
      this.getOrderList()
    }
  }
};
</script>

<style lang="scss" scoped>
</style>